namespace JGSY.CMS.LowCode.Platform.Domain.Enums;

/// <summary>
/// 系统错误码定义
/// </summary>
/// <remarks>
/// 错误码规范：
/// - 1xxx: 通用错误 (参数错误、权限不足等)
/// - 2xxx: 用户相关错误
/// - 3xxx: 分类相关错误
/// - 4xxx: 内容相关错误
/// - 5xxx: 系统错误
/// - 6xxx: 工作流相关错误
/// - 7xxx: 媒体文件相关错误
/// - 8xxx: 模板相关错误
/// - 9xxx: 权限相关错误
/// </remarks>
public static class ErrorCodes
{
    #region 通用错误 (1000-1999)
    
    /// <summary>
    /// 请求参数错误
    /// </summary>
    public const string INVALID_PARAMETERS = "1001";
    
    /// <summary>
    /// 访问被拒绝
    /// </summary>
    public const string ACCESS_DENIED = "1002";
    
    /// <summary>
    /// 资源未找到
    /// </summary>
    public const string RESOURCE_NOT_FOUND = "1003";
    
    /// <summary>
    /// 资源重复
    /// </summary>
    public const string DUPLICATE_RESOURCE = "1004";
    
    /// <summary>
    /// 操作不被允许
    /// </summary>
    public const string OPERATION_NOT_ALLOWED = "1005";

    /// <summary>
    /// 数据验证失败
    /// </summary>
    public const string VALIDATION_FAILED = "1006";

    /// <summary>
    /// 请求频率过高
    /// </summary>
    public const string RATE_LIMIT_EXCEEDED = "1007";

    /// <summary>
    /// 操作超时
    /// </summary>
    public const string OPERATION_TIMEOUT = "1008";

    #endregion

    #region 用户相关错误 (2000-2999)
    
    /// <summary>
    /// 用户未找到
    /// </summary>
    public const string USER_NOT_FOUND = "2001";
    
    /// <summary>
    /// 用户凭证无效
    /// </summary>
    public const string INVALID_CREDENTIALS = "2002";
    
    /// <summary>
    /// 用户已禁用
    /// </summary>
    public const string USER_INACTIVE = "2003";
    
    /// <summary>
    /// 密码已过期
    /// </summary>
    public const string PASSWORD_EXPIRED = "2004";
    
    /// <summary>
    /// 用户名已存在
    /// </summary>
    public const string USERNAME_EXISTS = "2005";
    
    /// <summary>
    /// 邮箱已存在
    /// </summary>
    public const string EMAIL_EXISTS = "2006";

    /// <summary>
    /// 手机号已存在
    /// </summary>
    public const string PHONE_EXISTS = "2007";

    /// <summary>
    /// 验证码错误
    /// </summary>
    public const string INVALID_VERIFICATION_CODE = "2008";

    /// <summary>
    /// 验证码已过期
    /// </summary>
    public const string VERIFICATION_CODE_EXPIRED = "2009";

    /// <summary>
    /// 密码强度不足
    /// </summary>
    public const string WEAK_PASSWORD = "2010";

    #endregion

    #region 分类相关错误 (3000-3999)
    
    /// <summary>
    /// 分类未找到
    /// </summary>
    public const string CATEGORY_NOT_FOUND = "3001";
    
    /// <summary>
    /// 分类名称已存在
    /// </summary>
    public const string CATEGORY_NAME_EXISTS = "3002";
    
    /// <summary>
    /// 分类编码已存在
    /// </summary>
    public const string CATEGORY_CODE_EXISTS = "3003";
    
    /// <summary>
    /// 分类包含子分类，无法删除
    /// </summary>
    public const string CATEGORY_HAS_CHILDREN = "3004";

    /// <summary>
    /// 分类包含内容，无法删除
    /// </summary>
    public const string CATEGORY_HAS_CONTENT = "3005";

    /// <summary>
    /// 分类层级超出限制
    /// </summary>
    public const string CATEGORY_DEPTH_EXCEEDED = "3006";

    /// <summary>
    /// 循环父子关系
    /// </summary>
    public const string CATEGORY_CIRCULAR_REFERENCE = "3007";

    #endregion

    #region 内容相关错误 (4000-4999)
    
    /// <summary>
    /// 内容未找到
    /// </summary>
    public const string CONTENT_NOT_FOUND = "4001";
    
    /// <summary>
    /// 内容已发布
    /// </summary>
    public const string CONTENT_ALREADY_PUBLISHED = "4002";
    
    /// <summary>
    /// 内容权限不足
    /// </summary>
    public const string CONTENT_PERMISSION_DENIED = "4003";

    /// <summary>
    /// 内容标题已存在
    /// </summary>
    public const string CONTENT_TITLE_EXISTS = "4004";

    /// <summary>
    /// 内容状态不允许操作
    /// </summary>
    public const string CONTENT_STATUS_NOT_ALLOWED = "4005";

    /// <summary>
    /// 内容正在审核中
    /// </summary>
    public const string CONTENT_UNDER_REVIEW = "4006";

    #endregion

    #region 系统相关错误 (5000-5999)
    
    /// <summary>
    /// 内部服务器错误
    /// </summary>
    public const string INTERNAL_SERVER_ERROR = "5000";
    
    /// <summary>
    /// 服务暂不可用
    /// </summary>
    public const string SERVICE_UNAVAILABLE = "5001";
    
    /// <summary>
    /// 请求超时
    /// </summary>
    public const string REQUEST_TIMEOUT = "5002";

    /// <summary>
    /// 数据库连接失败
    /// </summary>
    public const string DATABASE_CONNECTION_ERROR = "5003";

    /// <summary>
    /// 缓存服务异常
    /// </summary>
    public const string CACHE_SERVICE_ERROR = "5004";

    /// <summary>
    /// 文件系统错误
    /// </summary>
    public const string FILE_SYSTEM_ERROR = "5005";

    #endregion

    #region 工作流相关错误 (6000-6999)

    /// <summary>
    /// 工作流未找到
    /// </summary>
    public const string WORKFLOW_NOT_FOUND = "6001";

    /// <summary>
    /// 工作流状态错误
    /// </summary>
    public const string WORKFLOW_INVALID_STATUS = "6002";

    /// <summary>
    /// 审批权限不足
    /// </summary>
    public const string WORKFLOW_APPROVAL_DENIED = "6003";

    #endregion

    #region 媒体文件相关错误 (7000-7999)

    /// <summary>
    /// 文件未找到
    /// </summary>
    public const string FILE_NOT_FOUND = "7001";

    /// <summary>
    /// 文件格式不支持
    /// </summary>
    public const string FILE_FORMAT_NOT_SUPPORTED = "7002";

    /// <summary>
    /// 文件大小超出限制
    /// </summary>
    public const string FILE_SIZE_EXCEEDED = "7003";

    /// <summary>
    /// 文件上传失败
    /// </summary>
    public const string FILE_UPLOAD_FAILED = "7004";

    #endregion

    #region 模板相关错误 (8000-8999)

    /// <summary>
    /// 模板未找到
    /// </summary>
    public const string TEMPLATE_NOT_FOUND = "8001";

    /// <summary>
    /// 模板编译失败
    /// </summary>
    public const string TEMPLATE_COMPILE_ERROR = "8002";

    /// <summary>
    /// 模板渲染失败
    /// </summary>
    public const string TEMPLATE_RENDER_ERROR = "8003";

    #endregion

    #region 权限相关错误 (9000-9999)

    /// <summary>
    /// 角色未找到
    /// </summary>
    public const string ROLE_NOT_FOUND = "9001";

    /// <summary>
    /// 权限未找到
    /// </summary>
    public const string PERMISSION_NOT_FOUND = "9002";

    /// <summary>
    /// 角色权限不足
    /// </summary>
    public const string INSUFFICIENT_ROLE_PERMISSIONS = "9003";

    #endregion

    /// <summary>
    /// 获取错误码描述
    /// </summary>
    /// <param name="errorCode">错误码</param>
    /// <returns>错误描述</returns>
    public static string GetDescription(string errorCode)
    {
        return errorCode switch
        {
            INVALID_PARAMETERS => "请求参数错误",
            ACCESS_DENIED => "访问被拒绝",
            RESOURCE_NOT_FOUND => "资源未找到",
            DUPLICATE_RESOURCE => "资源重复",
            OPERATION_NOT_ALLOWED => "操作不被允许",
            VALIDATION_FAILED => "数据验证失败",
            RATE_LIMIT_EXCEEDED => "请求频率过高",
            OPERATION_TIMEOUT => "操作超时",
            
            USER_NOT_FOUND => "用户未找到",
            INVALID_CREDENTIALS => "用户凭证无效",
            USER_INACTIVE => "用户已禁用",
            PASSWORD_EXPIRED => "密码已过期",
            USERNAME_EXISTS => "用户名已存在",
            EMAIL_EXISTS => "邮箱已存在",
            PHONE_EXISTS => "手机号已存在",
            INVALID_VERIFICATION_CODE => "验证码错误",
            VERIFICATION_CODE_EXPIRED => "验证码已过期",
            WEAK_PASSWORD => "密码强度不足",
            
            CATEGORY_NOT_FOUND => "分类未找到",
            CATEGORY_NAME_EXISTS => "分类名称已存在",
            CATEGORY_CODE_EXISTS => "分类编码已存在",
            CATEGORY_HAS_CHILDREN => "分类包含子分类，无法删除",
            CATEGORY_HAS_CONTENT => "分类包含内容，无法删除",
            CATEGORY_DEPTH_EXCEEDED => "分类层级超出限制",
            CATEGORY_CIRCULAR_REFERENCE => "循环父子关系",
            
            CONTENT_NOT_FOUND => "内容未找到",
            CONTENT_ALREADY_PUBLISHED => "内容已发布",
            CONTENT_PERMISSION_DENIED => "内容权限不足",
            CONTENT_TITLE_EXISTS => "内容标题已存在",
            CONTENT_STATUS_NOT_ALLOWED => "内容状态不允许操作",
            CONTENT_UNDER_REVIEW => "内容正在审核中",
            
            INTERNAL_SERVER_ERROR => "内部服务器错误",
            SERVICE_UNAVAILABLE => "服务暂不可用",
            REQUEST_TIMEOUT => "请求超时",
            DATABASE_CONNECTION_ERROR => "数据库连接失败",
            CACHE_SERVICE_ERROR => "缓存服务异常",
            FILE_SYSTEM_ERROR => "文件系统错误",
            
            WORKFLOW_NOT_FOUND => "工作流未找到",
            WORKFLOW_INVALID_STATUS => "工作流状态错误",
            WORKFLOW_APPROVAL_DENIED => "审批权限不足",
            
            FILE_NOT_FOUND => "文件未找到",
            FILE_FORMAT_NOT_SUPPORTED => "文件格式不支持",
            FILE_SIZE_EXCEEDED => "文件大小超出限制",
            FILE_UPLOAD_FAILED => "文件上传失败",
            
            TEMPLATE_NOT_FOUND => "模板未找到",
            TEMPLATE_COMPILE_ERROR => "模板编译失败",
            TEMPLATE_RENDER_ERROR => "模板渲染失败",
            
            ROLE_NOT_FOUND => "角色未找到",
            PERMISSION_NOT_FOUND => "权限未找到",
            INSUFFICIENT_ROLE_PERMISSIONS => "角色权限不足",
            
            _ => "未知错误"
        };
    }
}
